package com.yc.store.mapper;

import com.yc.store.bean.Bill;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/4/27
 * Email haijunzhou@hnit.edu.cn
 */
@Mapper
public interface BillMapper {

    @Select("select * from bill")
    // <resultMap><result><assi..>
    // <resultMap> == @Results
    // @Result == <result>
    // <assi..> == @One
    @Results(
            id = "rm1",
            value = {
                    // id 主键映射 => 提升缓存性能, 建议配置
                    @Result( column = "id", property = "id", id = true ),
//                    @Result( column = "id", property = "id" ),  1 对 多  配置
                    @Result( column = "uid", property = "uid"),
                    @Result( column = "uid", property = "user",
                            one = @One(select = "com.yc.store.mapper.UserMapper.selectById")),
            }
    )
    public List<Bill> selectAll();

    @Insert("insert into bill values(default,#{type},#{custom},#{sums},now(),#{uid})")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void insert(Bill bill);

}
